﻿using System.Globalization;
using System.Web;
using SDCloudSolution.SDCloud.Web.Infrastructure.Interfaces;

namespace SDCloudSolution.SDCloud.Web.Infrastructure
{
    public class CultureInfoProvider : ICultureInfoProvider
    {
        public CultureInfo RetriveCultureInfoFromRequest(HttpRequestBase request)
        {
            var userLanguages = request.UserLanguages;
            if (userLanguages != null && userLanguages.Length > 0)
            {
                foreach (var userLanguage in userLanguages)
                {
                    try
                    {
                        var cultureInfo = new CultureInfo(userLanguage);
                        return cultureInfo;
                    }
                    catch (CultureNotFoundException)
                    {
                        
                    }
                }
            }

            return CultureInfo.CurrentCulture;
        }
    }
}